package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.system.Function;

public class Textarea extends Inputsuper{
	private static final long serialVersionUID = 5110122198261039406L;
	private Integer cols = 50; 
	private Integer rows = 5; 
	private Integer charsize=200;//字符数
	private String showinfo = null;//显示提示信息
	private String mesg = null;
	private String verifun = null;//自定义验证方法
	
	public int doStartTag()throws JspException{
		JspWriter jspOut = pageContext.getOut();
		NOOUT.put("value", true);
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		StringBuilder stringBuilder = new StringBuilder();
		String basePath = basepath(request);
		String pwidth = getWidth();
		pwidth =LenFormat((pwidth==null)?"350":pwidth);
		String heigth = getHeight();
		heigth =LenFormat((heigth==null)?"100":heigth);
		stringBuilder.append(potjs(request));//加载Prototype
		stringBuilder.append(nkUtiljs(request));//加载nkjs
		stringBuilder.append(nktextareaJS(request));//加载nkjs
		FormHtmlInsertid(getId(),getName(),getValue());
		stringBuilder.append("<textarea cols=\""+cols+"\" rows=\""+rows+"\" style=\"width:"+pwidth+";height: "+heigth+";border: 1px solid #AFAFAF;\"");
		stringBuilder.append(getBaseStr()+">");
		if(getValue()!=null){
			stringBuilder.append(getValue());
		}else{
			stringBuilder.append("");
		}
		stringBuilder.append("</textarea>");
		stringBuilder.append("<div id=\""+getId()+"_infoDiv\" style=\"width:"+pwidth+";\"></div>");
		stringBuilder.append("<script type=\"text/javascript\">");
		stringBuilder.append("Event.observe(document, 'dom:loaded', function() {");
		stringBuilder.append("var cfgs"+getId()+" = {");
		stringBuilder.append("id:'"+getId()+"',");
		stringBuilder.append("rurl:'"+basePath+"',");
		stringBuilder.append("charsize:"+charsize+",");
		if(null!=verifun){
			stringBuilder.append("verifun:function(a){return "+verifun+"(a);},");
		}
		if(null!=showinfo){
			stringBuilder.append("showinfo:"+"true".equals(showinfo)+",");
		}
		if(null!=mesg){
			stringBuilder.append("lang_mesg:'"+mesg+"',");
		}
		stringBuilder.append("lang_1:'"+Function.lung(request,"org_nokatag_Textarea_1")+"',");
		stringBuilder.append("lang_2:'"+Function.lung(request,"org_nokatag_Textarea_2")+"',");
		stringBuilder.append("lang_3:'"+Function.lung(request,"org_nokatag_Textarea_3")+"',");
		stringBuilder.append("lang_4:'"+Function.lung(request,"org_nokatag_Textarea_4")+"',");
		stringBuilder.append("lang_5:'"+Function.lung(request,"org_nokatag_Textarea_5")+"'");
		stringBuilder.append("};");
		stringBuilder.append("var np"+getId()+" = new ntextarea(cfgs"+getId()+");");
		stringBuilder.append("np"+getId()+".show();");
		stringBuilder.append("});");
		stringBuilder.append("</script>");
		try {
			jspOut.write(stringBuilder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}

	public String getVerifun() {
		return verifun;
	}

	public void setVerifun(String verifun) {
		this.verifun = verifun;
	}

	public Integer getCharsize() {
		return charsize;
	}

	public void setCharsize(Integer charsize) {
		this.charsize = charsize;
	}

	public Integer getCols() {
		return cols;
	}

	public void setCols(Integer cols) {
		this.cols = cols;
	}

	public Integer getRows() {
		return rows;
	}

	public void setRows(Integer rows) {
		this.rows = rows;
	}

	public String getShowinfo() {
		return showinfo;
	}

	public void setShowinfo(String showinfo) {
		this.showinfo = showinfo;
	}

	public String getMesg() {
		return mesg;
	}

	public void setMesg(String mesg) {
		this.mesg = mesg;
	}

}
